Imports KanBan.Pgd.Domain.ValueObjects

Namespace Entities

    Public Class GroupPermission

        Protected Sub New()

        End Sub

        Private _group As Group
        Public Overridable Property Group() As Group
            Get
                Return _group
            End Get
            Set(ByVal value As Group)
                _group = value
            End Set
        End Property

        Private _permission As Permission
        Public Overridable Property Permission() As Permission
            Get
                Return _permission
            End Get
            Set(ByVal value As Permission)
                _permission = value
            End Set
        End Property

        ''' <summary>
        ''' Indica si el la asignacion Grupo-Permiso se puede borrar o no.
        ''' </summary>
        ''' <remarks></remarks>
        Private _isDeletable As Boolean
        Public Overridable Property IsDeletable() As Boolean
            Get
                Return _isDeletable
            End Get
            Set(ByVal value As Boolean)
                _isDeletable = value
            End Set
        End Property

        Public Overloads Shared Function CreateGroupPermission(ByVal group As Group, ByVal permission As Permission, Optional ByVal isDeletable As Boolean = False) As GroupPermission

            Dim groupPermission As New GroupPermission()

            groupPermission.Group = group
            groupPermission.Permission = permission
            groupPermission.IsDeletable = isDeletable

            Return groupPermission

        End Function

        Public Overrides Function Equals(ByVal obj As Object) As Boolean

            If obj.GetType Is GetType(GroupPermission) Then

                Dim gp As GroupPermission = CType(obj, GroupPermission)
                If Me.Group.Id = gp.Group.Id And Me.Permission.Id = gp.Permission.Id Then
                    Return True
                Else
                    Return False
                End If
            End If

            Return False

        End Function

        Public Overrides Function GetHashCode() As Integer

            Return Me.Permission.Id.GetHashCode()

        End Function

    End Class

End Namespace
